package facetest.az26;

import org.junit.Test;

import java.util.concurrent.locks.LockSupport;

/**
 * 两个线程 交叉输出 A1B2C3......Z26
 */
public class LockSupportTest {
    static Thread t1, t2;
    String[] zimuArr = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", ",M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
    String[] numArr = new String[zimuArr.length];

    {
        for (int i = 0; i < zimuArr.length; i++) {
            numArr[i] = (i + 1) + "";
        }

    }

    @Test
    public void test() {

        t1 = new Thread(() -> {
            for (String s : zimuArr) {
                System.out.println(s);
                LockSupport.unpark(t2);
                LockSupport.park();
            }


        });
        t2 = new Thread(() -> {
            for (String s : numArr) {
                LockSupport.park();
                System.out.println(s);
                LockSupport.unpark(t1);
            }

        });
        t1.start();
        t2.start();

        while (true) ;
    }
}
